package com.gview.example.common;

import com.gonsin.gview.annotations.GViewScan;
import com.gonsin.gview.common.config.GViewResourceProperties;
import com.gonsin.gview.logic.EnableGView;
import com.gonsin.gview.logic.config.GViewMenuService;
import com.gonsin.gview.model.menu.GViewMenu;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@ComponentScan("com.gview.example.common")
@SpringBootApplication
@MapperScan("com.gview.example.common")

@EnableGView
@GViewScan("com.gview.example.common")
//
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }


    /**
     * 设置菜单
     * @return
     */
    @Bean
    public GViewMenuService gViewMenuConfig(){
        GViewMenuService config = new GViewMenuService() {

            @Override
            public List<GViewMenu> getMenus(HttpServletRequest request) {

                // 实际开发可以根据request内的session，构建不同用户的不同菜单内容

                List<GViewMenu> menus = new ArrayList<>();
                menus.add(new GViewMenu("BOOK_1", "图书管理（静态GView）", null, "view?viewName=BookView1", "el-icon-menu"));
                menus.add(new GViewMenu("BOOK_2", "图书管理（动态GView）", null, "view?viewName=BookView2", "el-icon-menu"));
                return menus;
            }
        };
        return config;
    }


    /**
     * 设置默认资源
     */
    @Bean
    public GViewResourceProperties resourceProperties(){
        GViewResourceProperties properties = new GViewResourceProperties();
        properties.setDefaultUsername("gview");
        properties.setDefaultPassword("gview");
        return properties;
    }

}